<template>
  <div id="category-detail" :style="'background: url(' + bgImg + ')  no-repeat center'">
    <div class="list">
      <div>
        <div class="header">
          <div class="big-point"/>
          <h2>{{category}}</h2>
        </div>
        <ul v-for="blog in blogs">
          <li @click="routeClick(blog.id)">
            <div class="point"/>
            <span class="time">{{blog.created}}</span>
            <span class="title">{{blog.title}}</span>
          </li>
        </ul>
      </div>
    </div>
    <header-inner class="header-inner"/>
    <side-bar-inner class="side-bar-inner"/>
  </div>
</template>

<script>
import {getBlogsByCategory} from "@/network/blogRequest";

import HeaderInner from "@/components/blog/blogs/HeaderInner";
import SideBarInner from "@/components/blog/blogs/SideBarInner";

import bgImg from "@/assets/background/明日方舟-情人节.jpg";

export default {
  name: "CategoryDetail",
  data() {
    return {
      bgImg,
      category: this.$route.params.category,
      blogs: []
    }
  },
  components: {
    HeaderInner,
    SideBarInner
  },
  methods: {
    /*网络请求*/
    getBlogsByCategory(category) {
      getBlogsByCategory(category).then(res => {
        this.blogs = res.data;
      })
    },

    /*事件监听*/
    routeClick(id) {
      this.$router.push("/blog/" + id);
    }
  },
  created() {
    const category = this.$route.params.category;
    this.getBlogsByCategory(category);
  }
}
</script>

<style scoped>
  ul {
    list-style: none;
  }

  #category-detail {
    overflow: auto;
    height: 100%;
  }

  #category-detail .list {
    position: absolute;
    top: 10px;
    left: 30%;
    width: 50%;
    padding: 40px 30px 40px 70px;
    border: 1px solid #d5d5d5;
    background-color: rgba(255,255, 255, 0.9);
    box-shadow: 5px 5px 5px 0 rgba(0, 0, 0, 0.3);
  }

  #category-detail .list .header .big-point {
    position: absolute;
    width: 10px;
    height: 10px;
    margin-top: 11px;
    margin-left: -7px;
    border-radius: 5px;
    background-color: #bbbbbb;
  }

  #category-detail .list .header h2 {
    margin-left: 20px;
    font-size: 22px;
  }

  #category-detail .list>div {
    border-left: 5px solid #f5f5f5;
  }

  #category-detail .list ul li {
    margin-top: 30px;
    color: #555555;
    border-bottom: 1px dashed #cccccc;
  }

  #category-detail .list ul li:hover {
    border-bottom: 1px dashed black;
    cursor: pointer;
  }

  #category-detail .list ul li .point {
    position: absolute;
    margin-top: 12px;
    margin-left: -4px;
    width: 4px;
    height: 4px;
    border-radius: 2px;
    background-color: #bbbbbb;
  }

  #category-detail .list ul li:hover .point {
    background-color: black;
  }

  #category-detail .list ul li .time {
    font-size: 12px;
    margin-left: 10px;
  }

  #category-detail .list ul li .title{
    margin-left: 20px;
    font-size: 18px;
  }

  #category-detail .header-inner {
    position: absolute;
    top: 10px;
    right: 71%;
    width: 12%;
  }

  #category-detail .side-bar-inner {
    position: absolute;
    top: 220px;
    right: 71%;
    width: 12%;
  }
</style>